/*
* @Author: Jone XIn
* @Date: 2022-02-05 21:41:46
 * @LastEditTime: 2022-02-05 23:19:13
* @Description: 用户操作_test
*/
import { Request, Response } from 'express';
import { getUserInfo } from '../../model/user/user';
import { successNews, catchErrNews, paramsErrNews } from '../../utils/resMessage';

class User {

    static userInstance: User;

    constructor() { }

    /**
     * get userInfo
     * @param req
     * @param res
     * @returns any
     */
    public async getUser(req: Request, res: Response) {

        const { name } = req.params;
        if (!name) return res.json(paramsErrNews());

        try {
            const userInfos = await getUserInfo(name);
            return res.json(successNews(userInfos));
        } catch (_) {
            res.json(catchErrNews(_));
        }
    }


    public static getUserInstance(): User {
        if (User.userInstance) {
            return User.userInstance;
        }
        User.userInstance = new User();
        return this.userInstance;
    }
}


export default User.getUserInstance();